package com.db.williamchart.renderer.executor;

import com.db.williamchart.data.AxisType;
import com.db.williamchart.data.Paddings;

public class MeasureHorizontalBarChartPaddings {

    public Paddings invoke(
            AxisType axisType,
            float labelsHeight,
            float xLastLabelWidth,
            float yLongestLabelWidth,
            float labelsPaddingToInnerChart
    ) {
        return measurePaddingsX(axisType, labelsHeight, xLastLabelWidth, labelsPaddingToInnerChart)
                .mergeWith(
                        measurePaddingsY(axisType, yLongestLabelWidth, labelsPaddingToInnerChart)
                );
    }

    private Paddings measurePaddingsX(
            AxisType axisType,
            float labelsHeight,
            float xLastLabelWidth,
            float labelsPaddingToInnerChart
    ) {
        if (!axisType.shouldDisplayAxisX()) {
            return new Paddings(0, 0, 0, 0);
        }

        return new Paddings(
                0,
                0,
                xLastLabelWidth / 2,
                labelsHeight + labelsPaddingToInnerChart
        );
    }

    private Paddings measurePaddingsY(
            AxisType axisType,
            float yLongestLabelWidth,
            float labelsPaddingToInnerChart
    ) {
        if (!axisType.shouldDisplayAxisY()) {
            return new Paddings(0, 0, 0, 0);
        }

        return new Paddings(
                yLongestLabelWidth + labelsPaddingToInnerChart,
                0,
                0,
                0
        );
    }
}
